package com.resource.provider.controller;


import com.commons.utils.Result;
import com.resource.interfaces.interfacex.SurveyService;
import com.shikonghualian.logicalhat.Param;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;

/**
 * @author try
 * @date 2020/06/29
 */
@RestController
@Api(description = "调查问卷")
@RequestMapping(value = "/survey")
public class SurveyController {

    @Resource
    SurveyService surveyService;

    @ApiOperation(value = "获取调查问卷")
    @ApiImplicitParams(
            {
                    @ApiImplicitParam(paramType = "query", name = "token", value = "鉴权参数", required = true, dataType = "String"),
                    @ApiImplicitParam(paramType = "query", name = "surveyId", value = "问卷id", required = true, dataType = "Integer")}
    )
    @RequestMapping(value = "/getSurvey", method = RequestMethod.GET)
    @ResponseBody
    public Result getSurvey(@Param("token") String token,@Param("surveyId") Integer surveyId) {
        return surveyService.getSurvey(token, surveyId);
    }

    @ApiOperation(value = "问卷管理-查询")
    @ApiImplicitParams(
            {
                    @ApiImplicitParam(paramType = "query", name = "token", value = "鉴权参数", required = true, dataType = "String"),
                    @ApiImplicitParam(paramType = "query", name = "pageIndex", value = "页码", required = true, dataType = "Integer", defaultValue = "1"),
                    @ApiImplicitParam(paramType = "query", name = "pageSize", value = "每页大小", required = true, dataType = "Integer", defaultValue = "10"),
                    @ApiImplicitParam(paramType = "query", name = "surveyName", value = "问卷名称", required = false, dataType = "String"),
                    @ApiImplicitParam(paramType = "query", name = "isRelease", value = "状态，0：未发布，1：已发布，2：已结束", required = false, dataType = "int"),
            }
    )
    @RequestMapping(value = "/search", method = RequestMethod.GET)
    @ResponseBody
    public Result selectByInfo(@Param("token") String token,
                               @RequestParam(value = "pageIndex", defaultValue = "1") Integer pageIndex,
                               @RequestParam(value = "pageSize", defaultValue = "10") Integer pageSize,
                               @Param("surveyName") String surveyName,@Param("isRelease") Integer isRelease) {
        return surveyService.selectByInfo(token, pageIndex, pageSize,surveyName,isRelease);
    }

}
